﻿<template>
  <div>
    <a-card :bordered="false" :bodyStyle="tstyle">

      <div class="table-page-search-wrapper" v-if="hasPerm('PriceList:page')">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="系统分类 ">
                <a-input v-model="queryParam.sysClass" allow-clear placeholder="请输入系统分类 " />
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="编码 ">
                <a-input v-model="queryParam.itemCode" allow-clear placeholder="请输入编码 " />
              </a-form-item>
            </a-col><template v-if="advanced">
              <a-col :md="8" :sm="24">
                <a-form-item label="名称 ">
                  <a-input v-model="queryParam.itemName" allow-clear placeholder="请输入名称 " />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="项目id ">
                  <a-input v-model="queryParam.itemId" allow-clear placeholder="请输入项目id " />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="规格 ">
                  <a-input v-model="queryParam.itemSpec" allow-clear placeholder="请输入规格 " />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="单位 ">
                  <a-input v-model="queryParam.units" allow-clear placeholder="请输入单位 " />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="单价 ">
                  <a-input v-model="queryParam.itemPrice" allow-clear placeholder="请输入单价 " />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="拼音码 ">
                  <a-input v-model="queryParam.inputCode" allow-clear placeholder="请输入拼音码 " />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="五笔码 ">
                  <a-input v-model="queryParam.inputCodeWb" allow-clear placeholder="请输入五笔码 " />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="门诊发票分类 ">
                  <a-select style="width: 100%" v-model="queryParam.classOnOutpRcpt" placeholder="请选择门诊发票分类 ">
                    <a-select-option v-for="(item, index) in classOnOutpRcptData" :key="index" :value="item.code">{{
                        item.name
                    }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="住院发票分类 ">
                  <a-select style="width: 100%" v-model="queryParam.classOnInpRcpt" placeholder="请选择住院发票分类 ">
                    <a-select-option v-for="(item, index) in classOnInpRcptData" :key="index" :value="item.code">{{
                        item.name
                    }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="经验管理分类 ">
                  <a-select style="width: 100%" v-model="queryParam.classOnReckoning" placeholder="请选择经验管理分类 ">
                    <a-select-option v-for="(item, index) in classOnReckoningData" :key="index" :value="item.code">{{
                        item.name
                    }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="财务分类 ">
                  <a-select style="width: 100%" v-model="queryParam.subjCode" placeholder="请选择财务分类 ">
                    <a-select-option v-for="(item, index) in subjCodeData" :key="index" :value="item.code">{{ item.name
                    }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="病案分类 ">
                  <a-select style="width: 100%" v-model="queryParam.classOnMr" placeholder="请选择病案分类 ">
                    <a-select-option v-for="(item, index) in classOnMrData" :key="index" :value="item.code">{{ item.name
                    }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="英文编码 ">
                  <a-input v-model="queryParam.forignCode" allow-clear placeholder="请输入英文编码 " />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="是否打折 ">
                  <a-select style="width: 100%" v-model="queryParam.feeTypeMask" placeholder="请选择是否打折 ">
                    <a-select-option v-for="(item, index) in feeTypeMaskData" :key="index" :value="item.code">{{
                        item.name
                    }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="操作员 ">
                  <a-input v-model="queryParam.operator" allow-clear placeholder="请输入操作员 " />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="录入日期 ">
                  <a-date-picker style="width: 100%" placeholder="请选择录入日期 " v-model="queryParam.enterDateDate"
                    @change="onChangeenterDate" />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="执行科室编码 ">
                  <a-select style="width: 100%" v-model="queryParam.performedByCode" placeholder="请选择执行科室编码 ">
                    <a-select-option v-for="(item, index) in performedByCodeData" :key="index" :value="item.code">{{
                        item.name
                    }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="执行科室名称 ">
                  <a-input v-model="queryParam.performedByName" allow-clear placeholder="请输入执行科室名称 " />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="说明 ">
                  <a-input v-model="queryParam.memo" allow-clear placeholder="请输入说明 " />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="备注1 ">
                  <a-input v-model="queryParam.back1" allow-clear placeholder="请输入备注1 " />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="备注2 ">
                  <a-input v-model="queryParam.back2" allow-clear placeholder="请输入备注2 " />
                </a-form-item>
              </a-col>

              <a-col :md="8" :sm="24">
                <a-form-item label="生产方式统计分类 ">
                  <a-input v-model="queryParam.siRemark1" allow-clear placeholder="请输入生产方式统计分类 " />
                </a-form-item>
              </a-col>

              <a-col :md="8" :sm="24">
                <a-form-item label="国家医保编码 ">
                  <a-input v-model="queryParam.nationCodeYb" allow-clear placeholder="请输入国家医保编码 " />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="类别 ">
                  <a-input v-model="queryParam.lb" allow-clear placeholder="请输入类别 " />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="项目标志 ">
                  <a-input v-model="queryParam.itemFlag" allow-clear placeholder="请输入项目标志 " />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="外检标志 ">
                  <a-input v-model="queryParam.outside" allow-clear placeholder="请输入外检标志 " />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="外检单位编码 ">
                  <a-input v-model="queryParam.outsideHospitalCode" allow-clear placeholder="请输入外检单位编码 " />
                </a-form-item>
              </a-col>

              <a-col :md="8" :sm="24">
                <a-form-item label="注册备案号 ">
                  <a-input v-model="queryParam.zcbah" allow-clear placeholder="请输入注册备案号 " />
                </a-form-item>
              </a-col>
            </template>

            <a-col :md="8" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
                <a @click="toggleAdvanced" style="margin-left: 8px"> {{ advanced ? '收起' : '展开' }}
                  <a-icon :type="advanced ? 'up' : 'down'" />
                </a>
              </span>
            </a-col>

          </a-row>
        </a-form>
      </div>
    </a-card>

    <a-card :bordered="false">
      <s-table ref="table" :columns="columns" :data="loadData" :alert="true" :rowKey="(record) => record.iD"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" :scroll="{ x: 2000, y: 600 }">
        <template class="table-operator" slot="operator" v-if="hasPerm('PriceList:add')">
          <a-button type="primary" v-if="hasPerm('PriceList:add')" icon="plus" @click="$refs.addForm.add()">增加
          </a-button>
        </template>
        <span slot="classOnOutpRcptscopedSlots" slot-scope="text">
          {{ '' | dictType(text) }}
        </span>
        <span slot="classOnInpRcptscopedSlots" slot-scope="text">
          {{ '' | dictType(text) }}
        </span>
        <span slot="classOnReckoningscopedSlots" slot-scope="text">
          {{ '' | dictType(text) }}
        </span>
        <span slot="subjCodescopedSlots" slot-scope="text">
          {{ '' | dictType(text) }}
        </span>
        <span slot="classOnMrscopedSlots" slot-scope="text">
          {{ '' | dictType(text) }}
        </span>
        <span slot="feeTypeMaskscopedSlots" slot-scope="text">
          {{ '' | dictType(text) }}
        </span>
        <span slot="performedByCodescopedSlots" slot-scope="text">
          {{ '' | dictType(text) }}
        </span>
        <span slot="action" slot-scope="text, record">
          <a v-if="hasPerm('PriceList:edit')" @click="$refs.editForm.edit(record)">编辑</a>
          <a-divider type="vertical" v-if="hasPerm('PriceList:edit') & hasPerm('PriceList:delete')" />
          <a-popconfirm v-if="hasPerm('PriceList:delete')" placement="topRight" title="确认删除？"
            @confirm="() => PriceListDelete(record)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </s-table>
      <add-form ref="addForm" @ok="handleOk" />
      <edit-form ref="editForm" @ok="handleOk" />
    </a-card>
  </div>
</template>
<script>
import { STable } from '@/components'
import moment from 'moment'
import { PriceListPage, PriceListDelete } from '@/api/modular/main/PriceListManage'
import addForm from './addForm.vue'
import editForm from './editForm.vue'
export default {
  components: {
    STable,
    addForm,
    editForm
  },
  data() {
    return {
      advanced: false, // 高级搜索 展开/关闭
      queryParam: {},
      columns: [
        {
          title: '项目id',
          align: 'center',
          dataIndex: 'itemId',
          width: 80,
        },
        {
          title: '编码',
          align: 'center',
          dataIndex: 'itemCode',
          width: 100
        },
        {
          title: "医保编码",
          align: 'center',
          dataIndex: 'nationCodeYb',
          width: 250,
          ellipsis: true
        },

        {
          title: '名称',
          align: 'center',
          dataIndex: 'itemName',
          width: 200,
          ellipsis: true
        },

        {
          title: '规格',
          align: 'center',
          dataIndex: 'itemSpec',
          width: 120,
          ellipsis: true
        },
        {
          title: '单位',
          align: 'center',
          dataIndex: 'units',
          width: 100,

        },
        {
          title: '单价',
          align: 'center',
          dataIndex: 'itemPrice',
          width: 100,

        },
        {
          title: '拼音码',
          align: 'center',
          dataIndex: 'inputCode',
          width: 100,

        },
        {
          title: '操作员',
          align: 'center',
          dataIndex: 'operator',
          width: 100,

        },
        {
          title: '执行科室',
          align: 'center',
          dataIndex: 'performedByName',
          width: 100,

        },
        {
          title: '说明',
          align: 'center',
          dataIndex: 'memo',
          width: 100,

        },
        {
          title: '备注1',
          align: 'center',
          dataIndex: 'back1',
          width: 100,
        },
        {
          title: '备注2',
          align: 'center',
          dataIndex: 'back2',
          width: 100,
        },

        {
          title: '类别',
          align: 'center',
          dataIndex: 'lb',
          width: 100,
        },
        {
          title: '项目标志',
          align: 'center',
          dataIndex: 'itemFlag',
          width: 100,

        },
        {
          title: '医保说明',
          align: 'center',
          dataIndex: 'itemYbMemo',
          width: 100,

        },
        {
          title: '外检标志',
          align: 'center',
          dataIndex: 'outside',
          width: 100

        },
        {
          title: '外检单位编码',
          align: 'center',
          dataIndex: 'outsideHospitalCode',
          width: 100
        },
        {
          title: '注册备案号',
          align: 'center',
          dataIndex: 'zcbah',
          width: 100
        }
      ],
      tstyle: { 'padding-bottom': '0px', 'margin-bottom': '10px' },
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        return PriceListPage(Object.assign(parameter, this.switchingDate())).then((res) => {
          return res.data
        })
      },
      classOnOutpRcptData: [],
      classOnInpRcptData: [],
      classOnReckoningData: [],
      subjCodeData: [],
      classOnMrData: [],
      feeTypeMaskData: [
        {
          value: "有",
          name: "是"
        },
        {
          value: "无",
          name: "否"
        }
      ],
      performedByCodeData: [],
      selectedRowKeys: [],
      selectedRows: []
    }
  },
  created() {
    if (this.hasPerm('PriceList:edit') || this.hasPerm('PriceList:delete')) {
      this.columns.push({
        title: '操作',
        width: 150,
        dataIndex: 'action',
        scopedSlots: { customRender: 'action' },
        fixed: 'right',
        align: 'center'
      })
    }
    const classOnOutpRcptOption = this.$options
    this.classOnOutpRcptData = classOnOutpRcptOption.filters['dictData']('')
    const classOnInpRcptOption = this.$options
    this.classOnInpRcptData = classOnInpRcptOption.filters['dictData']('')
    const classOnReckoningOption = this.$options
    this.classOnReckoningData = classOnReckoningOption.filters['dictData']('')
    const subjCodeOption = this.$options
    this.subjCodeData = subjCodeOption.filters['dictData']('')
    const classOnMrOption = this.$options
    this.classOnMrData = classOnMrOption.filters['dictData']('')
    const feeTypeMaskOption = this.$options
    this.feeTypeMaskData = feeTypeMaskOption.filters['dictData']('')
    const performedByCodeOption = this.$options
    this.performedByCodeData = performedByCodeOption.filters['dictData']('')
  },
  methods: {
    moment,
    /**
     * 查询参数组装
     */
    switchingDate() {
      const queryParamenterDate = this.queryParam.enterDateDate
      if (queryParamenterDate != null) {
        this.queryParam.enterDate = moment(queryParamenterDate).format('YYYY-MM-DD')
        if (queryParamenterDate.length < 1) {
          delete this.queryParam.enterDate
        }
      }
      const queryParamcREATE_DATE = this.queryParam.cREATE_DATEDate
      if (queryParamcREATE_DATE != null) {
        this.queryParam.cREATE_DATE = moment(queryParamcREATE_DATE).format('YYYY-MM-DD')
        if (queryParamcREATE_DATE.length < 1) {
          delete this.queryParam.cREATE_DATE
        }
      }
      const queryParammODIFY_DATE = this.queryParam.mODIFY_DATEDate
      if (queryParammODIFY_DATE != null) {
        this.queryParam.mODIFY_DATE = moment(queryParammODIFY_DATE).format('YYYY-MM-DD')
        if (queryParammODIFY_DATE.length < 1) {
          delete this.queryParam.mODIFY_DATE
        }
      }
      const queryParamdELETE_DATE = this.queryParam.dELETE_DATEDate
      if (queryParamdELETE_DATE != null) {
        this.queryParam.dELETE_DATE = moment(queryParamdELETE_DATE).format('YYYY-MM-DD')
        if (queryParamdELETE_DATE.length < 1) {
          delete this.queryParam.dELETE_DATE
        }
      }
      const obj = JSON.parse(JSON.stringify(this.queryParam))
      return obj
    },
    PriceListDelete(record) {
      PriceListDelete(record).then((res) => {
        if (res.success) {
          this.$message.success('删除成功')
          this.$refs.table.refresh()
        } else {
          this.$message.error('删除失败') // + res.message
        }
      })
    },
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    onChangeenterDate(date, dateString) {
      this.enterDateDateString = dateString
    },
    onChangecREATE_DATE(date, dateString) {
      this.cREATE_DATEDateString = dateString
    },
    onChangemODIFY_DATE(date, dateString) {
      this.mODIFY_DATEDateString = dateString
    },
    onChangedELETE_DATE(date, dateString) {
      this.dELETE_DATEDateString = dateString
    },
    handleOk() {
      this.$refs.table.refresh()
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    }
  }
}
</script>
<style lang="less">
.table-operator {
  margin-bottom: 18px;
}

button {
  margin-right: 8px;
}
</style>
